#include"../../include/chat_tool.h"
void chatroom_tool::pack_send(int fd,string data)
{
    string user_name, message, sender_name;
    sender_name = gun_like.user_search(fd);
    Json::Reader read;
    Json::Value root;
    if (!read.parse(data, root))
    {
        cout << "json格式错误" << endl;
        return;
    }
    if (!root.isMember("send_user"))
    {
        cout << "json状态错误" << endl;
        return;
    }
    else
    {
        user_name = root["send_user"].asString();
    }
    int to_fd = gun_like.user_search(user_name);
    cout<<"!!!"<<endl;
    if (to_fd == -1)
    {
        root["status"] = "";
        cout << "用户未登录" << endl;
        root["msg"] = "用户未登录";
        return ;
    }
    else
    {
        cout<<"!!!"<<endl;
        cout<<"!!!"<<endl;
        root["status"] = "download";
        cout<<"!!!"<<endl;
        root["receive_user"] = sender_name;
        cout<<"!!!"<<endl;
    } 
    string temp = root.toStyledString();
    cout << "返回值：" << temp << endl;
    send(to_fd, temp.c_str(), temp.size(), 0);
}